<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="/public/css/login.css">
</head>

<body>
	<div class="main">
		<div class="header">
			<a href="/">
				<img src="/public/img/logo3.png" alt="">
			</a>
			<h1>用户注册</h1>
		</div>
		<form id="register_form" action="/register" method="post">
			<div class="form-group">
				<label for="">邮箱</label>
				<input type="email" class="form-control" id="" name="email" placeholder="Email" autofocus>
			</div>
			<div class="form-group">
				<label for="">昵称</label>
				<input type="text" class="form-control" id="" name="name" placeholder="name" autofocus>
			</div>
			<div class="form-group">
				<label for="">密码</label>
				<input type="password" class="form-control" id="" name="password" placeholder="Password">
			</div>
			<div class="form-group">
				<label for="">性别</label>
				<label class="radio-inline">
					<input type="radio" name="gender" id="inlineRadio1" value="男" > 男
				</label>
				<label class="radio-inline">
					<input type="radio" name="gender" id="inlineRadio2" value="女"> 女
				</label>
			</div>
			<div class="form-group">
				<label for="">个人简介</label>
				<textarea class="form-control" rows="2" name="msg" value=""></textarea>
			</div>
			<input class="hidden" name="birthday" value="1995-11-25"></input>

			<button type="submit" class="btn btn-success btn-block">注册</button>
		</form>
		<div class="message">
			<p>已有账号? <a href="/login">点击登入</a>.</p>
		</div>
	</div>
</body>
<script src="/public/js/jquery.js"></script>
<script >
	$('#register_form').on('submit',function(e){
		e.preventDefault()
		var formData=$(this).serialize()
		console.log(formData)
		$.ajax({
			url:'/register',
			type:'post',
			data:formData,
			dataType:'json',
			success:function(data){
				var code=data.code
        // console.log(data)
        if(code===0){
        	window.location.href='/'
        }else if(code===1){
        	window.alert('邮箱或用户名已存在')
        }else if(code===500){
        	window.alert('服务端写入或读取文件错误')
        }
    }
})
	})

</script>
</html>
